<?php
namespace app\admin\controller;

use app\common\model\Gatherreg as GatherregModel;
/**
 * 报名人控制器
 * Class Gatherreg
 * @package app\index\controller
 */
class Gatherreg extends Base
{
    /**
     * [getIndex  报名活动列表]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getIndex()
    {
        $param = input('param.');
        $model = new GatherregModel;
        $map = [];
        $this->getPageAndSize($param);
        $user = $this->user;
        try{
            if(!empty($param['type'])){
                $map['g.type'] = $param['type'];
            }
            $field = 'gr.id,gr.addtime,gr.gather_id,g.title,g.starttime,g.endtime,g.maxnum,m.tel,m.username,gr.name,gr.tel btel,gr.cate,gr.islocal,gr.gotime,gr.job,gr.education,gr.animal,gr.emergency_name,gr.emergency_tel,gr.is_buddhist,gr.buddhist_content,gr.remark,gr.know,gr.referrer,gr.sex,gr.age';
            $count = $model->getCounts($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getGatherregByCondition($map, $this->from, $this->size,$field);
            foreach($lists as &$v){
                $v['starttime'] = date('Y-m-d H:i:s',$v['starttime']);
                $v['endtime'] = date('Y-m-d H:i:s',$v['endtime']);
                $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
            }
        }catch(\Exception $e){
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看报名活动列表',1,$user);
        return admin_json(1, '获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}